<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack"%>

<chiptrack:checkLogon sourcePage="userDefinedFieldsForPojectSetup.do"/>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.forecast.commons.Constants,
                 com.scalar.forecast.commons.SessionKeys"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>

<HTML>
<HEAD>
<TITLE> Map Project Setup Part Numbers </TITLE>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<SCRIPT language="JavaScript">
    var fieldName = "";
    var errors1 = "";
    var chipsLen = 0;
    var boardsLen = 0;
    var kitsLen = 0;
    var found = false;
    function save() {
        errors1="";
        found = false;
        for ( var i = 0; i < chipsLen ; i++ )
        {
            if ( document.mapPartNumbersForm['mapPartNumbers.chipsList['+i+'].replacingPartNumberId'].value != "-1" )
            {
                found = true;
                for ( var j = 0; j < chipsLen ; j++ )
                {
                    if ( document.mapPartNumbersForm['mapPartNumbers.chipsList['+j+'].originalPartNumberId'].value == document.mapPartNumbersForm['mapPartNumbers.chipsList['+i+'].replacingPartNumberId'].value )
                    {
                        errors1 = "<li> Replacing Part Number should be other than original Part Numbers";
                        document.mapPartNumbersForm['mapPartNumbers.chipsList['+i+'].replacingPartNumberId'].focus();
                        break;
                    }
                }
            }
        }
        for ( var i = 0; i < boardsLen ; i++ )
        {
            if ( document.mapPartNumbersForm['mapPartNumbers.boardsList['+i+'].replacingPartNumberId'].value != "-1" )
            {
                found = true;
                for ( var j = 0; j < boardsLen ; j++ )
                {
                    if ( document.mapPartNumbersForm['mapPartNumbers.boardsList['+j+'].originalPartNumberId'].value == document.mapPartNumbersForm['mapPartNumbers.boardsList['+i+'].replacingPartNumberId'].value )
                    {
                        errors1 = "<li> Replacing Part Number should be other than original Part Numbers";
                        document.mapPartNumbersForm['mapPartNumbers.boardsList['+i+'].replacingPartNumberId'].focus();
                        break;
                    }
                }
            }
        }
        for ( var i = 0; i < kitsLen ; i++ )
        {
            if ( document.mapPartNumbersForm['mapPartNumbers.kitsList['+i+'].replacingPartNumberId'].value  != "-1" )
            {
                found = true;
                for ( var j = 0; j < kitsLen ; j++ )
                {
                    if ( document.mapPartNumbersForm['mapPartNumbers.kitsList['+j+'].originalPartNumberId'].value == document.mapPartNumbersForm['mapPartNumbers.kitsList['+i+'].replacingPartNumberId'].value )
                    {
                        errors1 = "<li> Replacing Part Number should be other than original Part Numbers";
                        document.mapPartNumbersForm['mapPartNumbers.kitsList['+i+'].replacingPartNumberId'].focus();
                        break;
                    }
                }
            }
        }
        if ( !found )
        {
            errors1 = "<li> Please map atleast one part number"
        }
        if ( errors1 == "" ) {
            document.mapPartNumbersForm.action.value="save";
            document.mapPartNumbersForm.submit();
        }
        else{
            var pa = document.getElementById("errorsId");
            pa.innerHTML = "";
            pa = document.getElementById("infoId");
            pa.innerHTML = "";
            pa = document.getElementById("error");
            pa.innerHTML = errors1;
        }
    }
    function closeWindow( form ) {
        form.action.value = "edit";
        window.opener.enableFields();
        form['projectSetup.projectID'].value = document.mapPartNumbersForm.projectId.value;
        form.submit();
        window.close();
    }
</SCRIPT>
<HEAD>
<BODY>
<html:form name="mapPartNumbersForm" method="post"  action="/mapPartNumbers.do" scope="session" type="com.scalar.forecast.projectSetup.forms.MapPartNumbersForm" >

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
  <TBODY>
  <TR>
    <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>

<!-- from here your body starts -->
        <center><span class="NArialW">Map Project Setup Part Numbers</span></center>
        <BR>
        <nested:nest property="mapPartNumbers">
        <TABLE border="0">
        <% if ( !user1.isActionAllowed ( Functionality.PROJECT_SETUP, User.USER_ACTION_MODIFY ) ) { %>
                <tr><td colspan=5 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></font></td></tr> <% } %>

                <TR><TD colspan =5 class="NArialL" id="errorsId"><chiptrack:errors styleClass="NArialL" /></TD></TR>
                <TR><TD colspan =5 class="NArialL" id="infoId"><chiptrack:info styleClass="NArialL" /></TD></TR>
                <TR><TD colspan="5" align="left" class='NArialL'><font styleClass="NArialL" id="error" color="FF0000"/>&nbsp;</TD></TR>
                <TR bgColor=#993333>
                    <TD class="NArialL" align="center"><FONT style="color:#ffffff;">Original Part No.</FONT></TD>
                    <TD>&nbsp;</TD>
                    <TD class="NArialL" align="center"><FONT style="color:#ffffff;">Replacing Part No.</FONT></TD>
				</TR>
                <% int chipsLen = 0, boardsLen = 0, kitsLen = 0;%>
                <logic:equal name="showChips" value="TRUE">
                    <TR><TD colspan=5 align="left" bgcolor="#AAAAFF"><FONT CLASS="NArialL">CHIPS</FONT></TD></TR>
                    <nested:iterate name="mapPartNumbers" id="chips" property="chipsList">
                    <% chipsLen = chipsLen + 1; %>
                    <TR>
                        <TD ><nested:text name="chips" property="originalPartNumber" styleClass="txfield" readonly="true" /> </TD>
                        <TD>----->&nbsp;</TD>
                        <TD><nested:select name ="chips" property="replacingPartNumberId" styleClass="txfield">
                                <html:option value="-1">-- select --</html:option>
                                <html:options collection="availableChipsList" property="value" labelProperty="label"></html:options>
                             </nested:select>
                             <nested:hidden name="chips" property="originalPartNumberId" />
                        </TD>
                    </TR>
                    </nested:iterate>
                </logic:equal>
                <logic:equal name="showBoards" value="TRUE" >
                    <TR><TD colspan=5 align="left">&nbsp;</TD></TR>
                    <TR><TD colspan=5 align="left" bgcolor="#AAAAFF"><FONT CLASS="NArialL">BOARDS</FONT></TD></TR>
                    <nested:iterate name="mapPartNumbers" property="boardsList" id="boards" >
                    <% boardsLen = boardsLen + 1; %>
                    <TR>
                        <TD ><nested:text name="boards" property="originalPartNumber" styleClass="txfield" readonly="true"/> </TD>
                        <TD>----->&nbsp;</TD>
                        <TD><nested:select name ="boards" property="replacingPartNumberId" styleClass="txfield">
                                <html:option value="-1">-- select --</html:option>
                                <html:options collection="availableBoardsList" property="value" labelProperty="label"></html:options>
                             </nested:select>
                             <nested:hidden name="boards" property="originalPartNumberId" />
                        </TD>
                    </TR>
                    </nested:iterate><TR><TD colspan=6 align="left">&nbsp;</TD></TR>
                </logic:equal>
                <logic:equal name="showKits" value="TRUE">
                    <TR><TD colspan=5 align="left" bgcolor="#AAAAFF"><FONT CLASS="NArialL">KITS</FONT></TD></TR>
                    <nested:iterate name="mapPartNumbers"  property="kitsList" id="kits">
                    <% kitsLen = kitsLen + 1; %>
                    <TR>
                        <TD ><nested:text name="kits" property="originalPartNumber" styleClass="txfield" readonly="true"/> </TD>
                        <TD>----->&nbsp;</TD>
                        <TD><nested:select name ="kits" property="replacingPartNumberId" styleClass="txfield">
                                <html:option value="-1">-- select --</html:option>
                                <html:options collection="availableKitsList" property="value" labelProperty="label"></html:options>
                             </nested:select>
                             <nested:hidden name="kits" property="originalPartNumberId" />
                        </TD>
                    </TR>
                    </nested:iterate>
                </logic:equal>
                <script>
                    chipsLen  = '<%=chipsLen%>';
                    boardsLen = '<%=boardsLen%>';
                    kitsLen   = '<%=kitsLen%>';
                </script>
                <TR> <TD>&nbsp;</TD> </TR>
                <TR>
                    <TD colspan="6" align="center">
                    <chiptrack:restrictedLink functionality='<%=Functionality.PROJECT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:save();" onmouseover="window.status='Click here to Save';return true" onmouseout="window.status='';return true">
                       <IMG onmouseover="window.status='Click here to save';return true" title="Click here to Save" onmouseout="window.status='';return true" height=17  src="<%=chipTracContext%>/jsp/includes/images/save.gif" width=53  border=0>
                    </chiptrack:restrictedLink>&nbsp;&nbsp;&nbsp;&nbsp;
                       <a href="javascript:document.mapPartNumbersForm.reset();"><IMG onmouseover="window.status='Click here to Reset';return true" title="Click here to Reset" onmouseout="window.status='';return true" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0></a>&nbsp;&nbsp;&nbsp;&nbsp;
                    </TD>
                </TR>
                <TR> <TD colspan="6" align="center">
                    <a href="javascript:window.close();"  onMouseOver="window.status='Click here to close this window';return true" title='Click here to close this window'><font class='NArialL'><b>[Close this window]</b></font></a>
                </TD> </TR>
            </TABLE>
        </nested:nest>
        <input type="hidden" name="action" value="">
        <html:hidden property="projectId"/>
    </TD>
<!-- till here -->
  </TR>
  </TBODY>
</TABLE>
</html:form>
</BODY>
</HTML>

